package 剑指offer.Month7_07.day16;

import java.util.Arrays;
import java.util.Comparator;

public class 把数组排成最小的树 {
    public String PrintMinNumber(int [] numbers) {
        if(numbers == null || numbers.length == 0){
            return "";
        }
        String[] arr = new String[numbers.length];
        for (int i = 0; i < arr.length; i++) {
            arr[i] = Integer.toString(numbers[i]);
        }
        Arrays.sort(arr, new Comparator <String>(){
            public int compare(String s1, String s2){
                return (s1 + s2).compareTo(s2 + s1);
            }
        });
        StringBuilder str = new StringBuilder();
        for(String s:arr){
            str.append(s);
        }
        return str.toString();
    }
}
